/**
 * @param {number[][]} rectangles
 * @return {number}
*/
var countGoodRectangles = function(rectangles) {
  rectangles.sort((a, b) => {
    let aMin = Math.min(...a), bMin = Math.min(...b);
    return bMin - aMin;
  });
  let min = Math.min(...rectangles[0]), result = 1;
  for(let i = 1; i < rectangles.length; i++) {
    if(Math.min(...rectangles[i]) == min) {
      result++;
    } else {
      break;
    }
  }
  return result;
};
let rectangles = [[5,8],[3,9],[5,12],[16,5]];
console.log(countGoodRectangles(rectangles));
rectangles = [[2,3],[3,7],[4,3],[3,7]];
console.log(countGoodRectangles(rectangles));
